public class Solution495 {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ans=0;
        for (int i=0;i<timeSeries.length;i++){
            if (i!=timeSeries.length-1){
                if (timeSeries[i+1]-timeSeries[i]>duration){
                    ans=ans+duration;
                }else {
                    ans=ans+timeSeries[i+1]-timeSeries[i];
                }
            }else{
                ans=ans+duration;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution495().findPoisonedDuration(new int[]{1,2},2));
    }
}
